package com.cdeledu.thread3.c8.myselfthreadpool;

import java.util.concurrent.TimeUnit;

public class Test {
	
	public static void main(String[] args) throws InterruptedException {
		//定义线程池，初始化线程数量为2，核心线程数量为4，最大线程数量为6，任务队列最多运行10个任务
		final ThreadPool threadPool = new BasicThreadPool(2, 6, 4, 10);
		//定义20个任务并且提交给线程池
		for(int i=0; i<20; i++){
			threadPool.execute(() -> {
				try {
					TimeUnit.SECONDS.sleep(2);
					System.out.println(Thread.currentThread().getName() + " is running and done.");
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			});
		}
		
		for(;;){
			//不断输出线程池信息
			System.out.println("getActiveCount:" + threadPool.getActiveCount());
			System.out.println("getQueueSize:" + threadPool.getQueueSize());
			System.out.println("======================================");
			TimeUnit.SECONDS.sleep(1);
		}
	}

}
